<?php 
set_time_limit(0) ;
if(session_start()) ;
	
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
	<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
	<script src="jquery.easing.1.3.js" type="text/javascript"></script>
	<script src="./jqueryFileTree/jqueryFileTree.js" type="text/javascript"></script>
	<script src="./jquery-ui-1.8.1.custom/js/jquery-ui-1.8.1.custom.min.js" type="text/javascript"></script>
	<link type="text/css" href="./jquery-ui-1.8.1.custom/css/smoothness/jquery-ui-1.8.1.custom.css"  rel="Stylesheet" />	
	<link type="text/css" href="./jquery-ui-1.8.1.custom/css/smoothness/jquery-ui-1.8.1.custom.css"  rel="Stylesheet" />	

	
	<link href="./jqueryFileTree/jqueryFileTree.css" rel="stylesheet" type="text/css" media="screen" />
	<link href="./style/main.css" rel="stylesheet" type="text/css" media="screen" />
 

		<script type="text/javascript">
					

		/*radioHandler works only if you put it out of the jquery's $(document).ready()*/
		function radioHandler(who){
				 
				pathSelection_ID = $(who).attr('radioSessionVariableName');
				pathSelection_VALUE =  $(who).val();
				//ONDEBUG  alert("pathSelection_ID: " + pathSelection_ID +"\npathSelection_VALUE: " + pathSelection_VALUE);
				$.post('./ajax/sessionifier.php', { name: pathSelection_ID,  value:  pathSelection_VALUE},
			   function(data){
				//ONDEBUG alert("Data Stored in session: " + data);
				refresh_sessiondatas("data_process","SPAN__data_process");

				});	 
		}
							
 
				
			$(document).ready( function() {
			
				 var refreshId= -1; // declaration for the object identifier for the refresh activity information
			

				radioSessionVariableNameVAL = $('#fileTree_drive_left').attr("radioSessionVariableName");
				$('#fileTree_drive_left').fileTree({radioSessionVariableName: radioSessionVariableNameVAL, radioFunction: 'radioHandler(this);',  radioNamePrefix : 'drive_left', letterDrive : 'c:\\', root: '/', script: './jqueryFileTree/connectors/jqueryFileTree.php' , folderEvent: 'click', expandSpeed: 750, collapseSpeed: 750, expandEasing: 'easeOutBounce', collapseEasing: 'easeOutBounce', multiFolder: false }, function(file) { 
					//if(debug) alert(file);
				});
				
				radioSessionVariableNameVAL = $('#fileTree_drive_right').attr("radioSessionVariableName");
				$('#fileTree_drive_right').fileTree({radioSessionVariableName: radioSessionVariableNameVAL, radioFunction: 'radioHandler(this);', radioNamePrefix : 'drive_right', letterDrive : 'c:\\', root: '/', script: './jqueryFileTree/connectors/jqueryFileTree.php', folderEvent: 'click', expandSpeed: 750, collapseSpeed: 750, expandEasing: 'easeOutBounce', collapseEasing: 'easeOutBounce', multiFolder: false }, function(file) { 
					//if(debug) alert(file);
				});

					
				
			
				
				 
				$(".drive_selector").change(function() {

						drive_selector_ID = $(this).attr('id');
 						drive_selector_VALUE =  $(this).val();
						radioSessionVariableNameVAL = $('#fileTree_'+ drive_selector_ID).attr("radioSessionVariableName");
						
						$.post('./ajax/sessionifier.php', { name: drive_selector_ID,  value:  drive_selector_VALUE},
					   function(data){
						 //ONDEBUG alert("Data Stored in session: " + data);
						 refresh_sessiondatas("data_process","SPAN__data_process");
							
							$('#fileTree_'+ drive_selector_ID).fileTree({radioSessionVariableName: radioSessionVariableNameVAL, radioFunction: 'radioHandler(this);', radioNamePrefix : drive_selector_ID, letterDrive : ''+drive_selector_VALUE+':\\', root: '/', script: './jqueryFileTree/connectors/jqueryFileTree.php', folderEvent: 'click', expandSpeed: 750, collapseSpeed: 750, expandEasing: 'easeOutBounce', collapseEasing: 'easeOutBounce', multiFolder: false }, function(file) { 
								//if(debug) alert(file);
							});						 

						});	 
				});
				 
 
				/*Workaround to make the refresh_sessiondatas visible outer of the $ scope*/
				window.refresh_sessiondatas = function(where, who){
					refresh_sessiondatas(where, who);
				} 
				
				
				function refresh_sessiondatas(where, who){
					$( "#"+where+" ."+ who).each(function(index) {
						refresh_sessiondata( $(this).attr('id'));
						//if(debug) alert(index + ': ' + $(this).text());
					  });
				}
				
				/*doesn't work*/
				$("input[name=drive_left_directory_name]").change(
					function(){
						alert($(this).val());
					
					}
				);
	
				

				
				
				
				function refresh_sessiondata(who){

					
					/*if not exists loader it creates it*/
					if (!$("#"+who+"__LOADER").length > 0){
					 $( "#"+who).parent().append("<span id=\""+who+"__LOADER	"+"\"><img style=\"width:16px;height:16px;\" src=\"./img/load.gif\"/></span>");
					 $("#"+who+"__LOADER").css('display', 'inline'); 
					 $("#"+who+"__LOADER").css('float', 'right'); 
					}
					/*otherwise shows it*/
						
					else {
						$("#"+who+"__LOADER").show(600);
						$("#"+who+"__VALUE").hide(600);
					}
					
					/*retrieves the value of the session variable*/
					//ONDEBUG alert("now I'm calling the S_SESSION.php passing him:'"+ $("#"+who).attr('value') + "'");
					
					$.post('./ajax/S_SESSION.php', { name: $("#"+who).attr('value')},
						   function(data){
							   
							 
							   
							$( "#"+who+"__LOADER").hide(600);
							 
							/*if not exists a value element it creates it*/
							if (!$("#"+who+"__VALUE").length > 0){
							 $( "#"+who).parent().append("<span class=\"flatspan\" id=\""+who+"__VALUE	"+"\">"+data+"</span>");
							 $("#"+who+"__VALUE").css('display', 'inline'); 
							 $("#"+who+"__VALUE").css('float', 'right'); 
	 
							}
							/*otherwise shows it*/
							else {
								$("#"+who+"__VALUE").html ("<span class=\"flatspan\">"+data+"</span>");
								$("#"+who+"__VALUE").show(600);
							}
						});	 
					
					
				}				
				
				
/*


   ___  ___   ___  ___  _   _  _               _  _       _    _              _                _          
  / __|/ _ \ | _ \| __|(_) (_)| |_   __  __ _ | || | ___ | |_ | |_   ___   __| | ___     _ __ | |_   _ __ 
 | (__| (_) ||   /| _|  _  | ||  _| / _|/ _` || || |(_-< |  _|| ' \ / -_) / _` |/ _ \ _ | '_ \| ' \ | '_ \
  \___|\___/ |_|_\|___|(_) |_| \__| \__|\__,_||_||_|/__/  \__||_||_|\___| \__,_|\___/(_)| .__/|_||_|| .__/
                                                                                        |_|         |_|   


*/				
				
				
				
				$("#start").click(function(){
					$("#dialog-modal").dialog({
								width: 320,
								height: 160,
								show: 'explode',
								hide: 'puff',
								modal: true,
								buttons: {
									'Yes, do the comparison.': function() {
									
										//CALLS TWO INSTANCES OF THE LANDER IN ORDER TO MAKE COMPARISON
										$('#status').load('do.php');
										
									
										$(this).dialog('close');
									},
									Cancel: function() {
										$(this).dialog('close');
									}
								}
								
							});
				});

//TRUNCATES TABLE
				$("#truncate").click(function(){
					$("#dialog-modal").dialog({
								width: 320,
								height: 160,
								show: 'explode',
								hide: 'puff',
								modal: true,
								buttons: {
									'Yes, TRUNCATE ALL TABLES.': function() {
									
										//CALLS TWO INSTANCES OF THE LANDER IN ORDER TO MAKE COMPARISON
										$('#status').load('truncate.php');
										
									
										$(this).dialog('close');
									},
									Cancel: function() {
										$(this).dialog('close');
									}
								}
								
							});
				});

				
// start statistics

   $("#start_statistics").click(function()
   {
 
   if (refreshId==-1){
		   clearTimeout(refreshId);
		   refreshId = setTimeout(function()
		   {
			 $('#statistics').load('statistics.php');
		   }, 1000);
	   }
   });

   
   $("#get_statistics").click(function()
   {
	 $('#statistics').load('statistics.php');
   });   
   
   
   
   //stop the clock when this button is clicked
   $("#stop_statistics").click(function()
   {
     clearTimeout(refreshId);
	 refreshId=-1;
   });				
				
				
				
			});
		</script>

	
	</head>
	<body>



		<h1>Lander</h1>
		<h4 style="color:#dd4444;">lookin another directory erelong</h4>
		<!--div id="div00001" style="width:500px;height:600px;background-color:#eee;">aaa</div-->
		

			<div id="communication_console" class="lander_maincss">
			<!--Comunicazioni-->
			</div>

 
		
	<table style="display:block; float:none; width:90%;">		
		<tr style="width:900px;">
			<td style="width:900px;">	
				<form name="f_left" id = "f_left">
					<div class="lander_maincss">
						<h2>Left Folder</h2>
						<?php
						echo "<select name=\"testname\" class=\"drive_selector\" id=\"drive_left\"><option>Drive Left</option>";
						for ($ii=66;$ii<92;$ii++) 
						{
							$char = chr($ii);
							if (opendir($char.":/"))
								echo "<option>".$char."</option>";
						}
						echo "</select>";
						?>
						<input type="checkbox"  id="LeftDriveOnly" value="DriveOnly"/>Drive Only
						<div id="fileTree_drive_left" radioSessionVariableName="path_left" class="demo"></div>
					</div>
				</form>

				<form name="f_right" id = "f_right">
					<div class="lander_maincss">
					
						<h2>Right Folder</h2>
						<?php
						echo "<select class=\"drive_selector\" id = 'drive_right'><option>Drive Right</option>";
						for ($ii=66;$ii<92;$ii++) 
						{
							$char = chr($ii);
							if (opendir($char.":/"))
								echo "<option>".$char."</option>";
						}
						echo "</select>";
						?>	
						<input type="checkbox"  id="RightDriveOnly" value="DriveOnly"/>Drive Only						
						<div id="fileTree_drive_right" radioSessionVariableName="path_right" class="demo"></div>
					</div>
				</form>	 
				<form name="data_process" id = "data_process">
					<div class="lander_maincss">
					
						<h2>Selected info:</h2>
							<h4>Left drive:
								<input type="hidden" class="HI__data_process" value="drive_left" id="HI__left_drive_span" name="HI__left_drive_span">
								<span class="SPAN__data_process" value="drive_left" id="drive_left_span"></span>
							</h4>
							<h4>Right drive:
								<input type="hidden" class="HI__data_process" value="drive_right" id="HI__left_folder_span" name="HI__left_folder_span">
								<span class="SPAN__data_process" value="drive_right" id="drive_right_span"></span>
							</h4>
							<h4>Left Folder:
								<input type="hidden" class="HI__data_process" value="path_left" id="HI__right_drive_span" name="HI__right_drive_span">
								<span class="SPAN__data_process" value="path_left" id="path_left_span"></span>
							</h4>
							<h4>Right folder:
								<input type="hidden" class="HI__data_process" value="path_right" id="HI__right_folder_span" name="HI__right_folder_span">
								<span class="SPAN__data_process" value="path_right" id="path_right_span"></span>
							</h4>
						 
					</div>
				</form>	
			</td>	
		</tr>	
		<tr style=" width:210px">
			<td style=" width:110px">		
			<div style="display:block; float:left; ">	
				<img id="start" src="startx48.png">
				</img>
			</div>	
			<div id="dialog-modal" title="Question">
				<p>Now it will be created a new  comparison session in the Lander database.</p> 
			</div>
			<div style="display:block; float:left; ">	
				<input type="button" id="truncate" value="Truncate Tables"/>
			
			</div>	
			<div id="dialog-modal" title="Question">
				<p>Now it will be created a new  comparison session in the Lander database.</p> 
			</div>			
			
			<div id="status" style="display:block; float:left;">
			</div>
			

			<div style="display:block; float:left; ">	
				<input type="button" id="start_statistics" disabled value="Start Statistics"/>
				<input type="button" id="stop_statistics" disabled value="Stop Statistics"/>
				<input type="button" id="get_statistics"  value="Get Statistics"/>
				<div id="statistics"/>
			</div>			
			</td>	
			
		</tr>	
	</table>	
	</body>
</html>